﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d"
    Margin="20"
	x:Class="MvvmFx.Samples.HowTos.Validation.DeliveryView"
	x:Name="UserControl" >

    <UserControl.Resources>

        <!--x:Key="textBlockInError"-->
        <Style  TargetType="{x:Type TextBlock}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter 
          Property="ToolTip"
          Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"
        />
                </Trigger>
            </Style.Triggers>
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <DockPanel DockPanel.Dock="Right">
                            <AdornedElementPlaceholder/>
                            <Image 
             Source="/Images/Error.png" 
             Width="16" 
             Height="16"
             ToolTip="{Binding Path=AdornedElement.ToolTip, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Adorner}}}"
          />
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <!--x:Key="textBoxInError"-->
        <Style 
               TargetType="{x:Type TextBox}" >
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip"
                Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"
        />
                </Trigger>
            </Style.Triggers>
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <DockPanel DockPanel.Dock="Right">
                            <AdornedElementPlaceholder/>
                            <Image 
              Source="/Images/Error.png" 
              Width="16" 
              Height="16"
              ToolTip="{Binding Path=AdornedElement.ToolTip, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Adorner}}}"
            />
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <Style x:Key="comboBoxInError" TargetType="{x:Type ComboBox}" >
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter
          Property="ToolTip"
          Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"
        />
                </Trigger>
            </Style.Triggers>
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <DockPanel DockPanel.Dock="Right">
                            <AdornedElementPlaceholder/>
                            <Image 
             Source="/Images/Error.png" 
             Width="16" 
             Height="16"
             ToolTip="{Binding Path=AdornedElement.ToolTip, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Adorner}}}"
          />
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>


    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="34"/>
            <RowDefinition Height="34"/>
            <RowDefinition Height="34"/>
            <RowDefinition Height="34"/>
            <RowDefinition Height="34"/>
        </Grid.RowDefinitions>
        <TextBlock TextWrapping="Wrap" Text="Flat/House No." VerticalAlignment="Center" HorizontalAlignment="Left" Width="104" Height="14.584" d:LayoutOverrides="GridBox" />
        <TextBox TabIndex="6" 
                 Text="{Binding HouseNameNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, FallbackValue=2, ValidatesOnDataErrors=True}" 
                 VerticalAlignment="Center" Margin="117,0,95,0" Height="21.96" d:LayoutOverrides="GridBox" />
        <TextBlock TextWrapping="Wrap" Text="Street Name:" Grid.Row="1"  HorizontalAlignment="Left" Width="112" Height="14.584" d:LayoutOverrides="GridBox" />
        <TextBox Grid.Row="1" TabIndex="6" 
                 Text="{Binding StreetName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, FallbackValue=Harberton Road, ValidatesOnDataErrors=True}" VerticalAlignment="Center" Margin="117,0,95,0" Height="21.96" d:LayoutOverrides="GridBox" />
        <TextBlock TextWrapping="Wrap" Grid.Row="2" Text="City Name:" HorizontalAlignment="Left" Width="112" Height="14.584" d:LayoutOverrides="GridBox" />
        <TextBox Grid.Row="2" TabIndex="6" Text="{Binding CityName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, FallbackValue=London, ValidatesOnDataErrors=True}" VerticalAlignment="Center" Margin="117,0,95,0" Height="21.96" d:LayoutOverrides="GridBox" />
        <TextBlock TextWrapping="Wrap" Grid.Row="3" Text="Country:" HorizontalAlignment="Left" Width="112" Height="14.584" d:LayoutOverrides="GridBox" />
        <TextBox Grid.Row="3" TabIndex="6" Text="{Binding Country, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, FallbackValue=UK, ValidatesOnDataErrors=True}" VerticalAlignment="Center" Margin="117,0,95,0" Height="21.96" d:LayoutOverrides="GridBox" />
        <TextBlock TextWrapping="Wrap" Grid.Row="4" Text="Post Code:" HorizontalAlignment="Left" Width="112" Height="14.584" d:LayoutOverrides="GridBox" />
        <TextBox Grid.Row="4" TabIndex="6" Text="{Binding PostCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, FallbackValue=N1 8RN, ValidatesOnDataErrors=True}" VerticalAlignment="Center" Margin="117,0,95,0" Height="21.96" d:LayoutOverrides="GridBox" />

    </Grid>
</UserControl>